<template>
  <div class="settings-store">
    <a-card class="settings-card">
      <template #title>店铺设置</template>
      <a-form :model="storeForm" layout="vertical">
        <div class="settings-group">
          <div class="group-title">基本信息</div>
          <a-row :gutter="16">
            <a-col :span="12">
              <a-form-item field="storeName" label="店铺名称">
                <a-input
                  v-model="storeForm.storeName"
                  placeholder="请输入店铺名称"
                />
              </a-form-item>
            </a-col>
            <a-col :span="12">
              <a-form-item field="category" label="主营类目">
                <a-select
                  v-model="storeForm.category"
                  placeholder="请选择主营类目"
                  multiple
                >
                  <a-option value="cultural">文创用品</a-option>
                  <a-option value="handcraft">手工艺品</a-option>
                  <a-option value="souvenir">特色纪念品</a-option>
                  <a-option value="food">地方特产</a-option>
                  <a-option value="tea">茶叶茶具</a-option>
                  <a-option value="ceramic">陶瓷制品</a-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>

          <a-form-item field="description" label="店铺简介">
            <a-textarea
              v-model="storeForm.description"
              placeholder="请输入店铺简介，建议包含店铺特色、主营产品等信息"
              :max-length="200"
              show-word-limit
            />
          </a-form-item>

          <a-form-item field="announcement" label="店铺公告">
            <a-textarea
              v-model="storeForm.announcement"
              placeholder="请输入店铺公告，如优惠活动、新品上架等信息"
              :max-length="100"
              show-word-limit
            />
          </a-form-item>
        </div>

        <a-divider />

        <div class="settings-group">
          <div class="group-title">店铺装修</div>
          <a-form-item field="banner" label="店铺横幅">
            <a-upload
              list-type="picture-card"
              :file-list="storeForm.banner"
              :limit="5"
              @change="handleBannerChange"
            >
              <template #upload-button>
                <div class="upload-button">
                  <icon-plus />
                  <div class="upload-text">上传图片</div>
                </div>
              </template>
            </a-upload>
            <div class="form-item-tip">建议尺寸：1200x300px，最多上传5张</div>
          </a-form-item>

          <a-form-item field="theme" label="店铺风格">
            <a-radio-group v-model="storeForm.theme">
              <a-space direction="vertical">
                <a-radio value="cultural">
                  <div class="theme-option">
                    <div class="theme-preview cultural-theme"></div>
                    <span>文创风格</span>
                  </div>
                </a-radio>
                <a-radio value="traditional">
                  <div class="theme-option">
                    <div class="theme-preview traditional-theme"></div>
                    <span>传统风格</span>
                  </div>
                </a-radio>
                <a-radio value="modern">
                  <div class="theme-option">
                    <div class="theme-preview modern-theme"></div>
                    <span>现代简约</span>
                  </div>
                </a-radio>
              </a-space>
            </a-radio-group>
          </a-form-item>
        </div>

        <a-divider />

        <div class="settings-group">
          <div class="group-title">配送设置</div>
          <a-form-item field="shippingMethod" label="配送方式">
            <a-checkbox-group v-model="storeForm.shippingMethod">
              <a-space direction="vertical">
                <a-checkbox value="express">快递发货</a-checkbox>
                <a-checkbox value="self">门店自提</a-checkbox>
              </a-space>
            </a-checkbox-group>
          </a-form-item>

          <a-form-item field="shippingRules" label="运费规则">
            <a-radio-group v-model="storeForm.shippingRules.type">
              <a-radio value="free">全场包邮</a-radio>
              <a-radio value="condition">满额包邮</a-radio>
              <a-radio value="weight">按重量计费</a-radio>
            </a-radio-group>

            <div
              v-if="storeForm.shippingRules.type === 'condition'"
              class="mt-4"
            >
              <a-input-number
                v-model="storeForm.shippingRules.freeLimit"
                :min="0"
                :step="10"
                prefix="￥"
                placeholder="请输入包邮金额"
              />
              <span class="ml-2">元起包邮</span>
            </div>

            <div v-if="storeForm.shippingRules.type === 'weight'" class="mt-4">
              <a-input-number
                v-model="storeForm.shippingRules.basePrice"
                :min="0"
                :step="1"
                prefix="￥"
                placeholder="首重费用"
              />
              <span class="ml-2">元（首重1kg）</span>
              <a-input-number
                v-model="storeForm.shippingRules.additionalPrice"
                :min="0"
                :step="1"
                prefix="￥"
                class="ml-4"
                placeholder="续重费用"
              />
              <span class="ml-2">元/kg</span>
            </div>
          </a-form-item>

          <a-form-item field="specialAreas" label="特殊地区">
            <a-checkbox-group v-model="storeForm.specialAreas">
              <a-space direction="vertical">
                <a-checkbox value="xinjiang"
                  >新疆、西藏等偏远地区不包邮</a-checkbox
                >
                <a-checkbox value="hongkong">港澳台地区不支持配送</a-checkbox>
                <a-checkbox value="overseas">不支持海外配送</a-checkbox>
              </a-space>
            </a-checkbox-group>
          </a-form-item>

          <a-form-item
            field="selfPickupAddress"
            label="自提地址"
            v-if="storeForm.shippingMethod.includes('self')"
          >
            <a-input
              v-model="storeForm.selfPickupAddress"
              placeholder="请输入门店自提地址"
            />
          </a-form-item>
        </div>

        <a-divider />

        <div class="settings-group">
          <div class="group-title">交易设置</div>
          <a-form-item field="minOrder" label="起售金额">
            <a-input-number
              v-model="storeForm.minOrder"
              :min="0"
              :step="10"
              prefix="￥"
              placeholder="请输入起售金额"
            />
            <div class="form-item-tip">设置为0则不限制最低消费</div>
          </a-form-item>

          <a-form-item field="businessTime" label="客服时间">
            <a-time-picker
              v-model="storeForm.businessTime.start"
              style="width: 120px"
            />
            <span class="mx-2">至</span>
            <a-time-picker
              v-model="storeForm.businessTime.end"
              style="width: 120px"
            />
            <div class="form-item-tip">
              设置在线客服服务时间，显示在店铺页面
            </div>
          </a-form-item>
        </div>

        <a-form-item>
          <a-button type="primary" @click="handleSaveStore">
            保存设置
          </a-button>
        </a-form-item>
      </a-form>
    </a-card>
  </div>
</template>

<script setup>
import { reactive } from "vue";
import { Message } from "@arco-design/web-vue";
import { IconPlus } from "@arco-design/web-vue/es/icon";

const storeForm = reactive({
  storeName: "贵港文创商城",
  category: ["cultural", "handcraft"],
  description: "专注贵港本地文创产品销售，提供优质的文化创意商品。",
  announcement: "欢迎光临本店，新品上架，优惠多多！",
  banner: [],
  theme: "cultural",
  shippingMethod: ["express"],
  shippingRules: {
    type: "condition",
    freeLimit: 99,
    basePrice: 8,
    additionalPrice: 5,
  },
  specialAreas: ["xinjiang", "overseas"],
  selfPickupAddress: "",
  minOrder: 0,
  businessTime: {
    start: "09:00:00",
    end: "21:00:00",
  },
});

const handleBannerChange = (fileList) => {
  storeForm.banner = fileList;
};

const handleSaveStore = () => {
  Message.success("店铺设置已保存");
};
</script>

<style lang="scss" scoped>
.settings-store {
  .settings-card {
    @apply mb-6;

    .settings-group {
      @apply mb-6;

      .group-title {
        @apply text-base font-medium mb-4;
      }
    }
  }

  .upload-button {
    @apply flex flex-col items-center justify-center;

    .upload-text {
      @apply mt-2 text-sm text-gray-500;
    }
  }

  .theme-option {
    @apply flex items-center gap-4;

    .theme-preview {
      @apply w-32 h-20 rounded-lg border border-gray-200;

      &.cultural-theme {
        @apply bg-gradient-to-r from-red-500 to-yellow-500;
      }

      &.traditional-theme {
        @apply bg-gradient-to-r from-amber-700 to-yellow-600;
      }

      &.modern-theme {
        @apply bg-gradient-to-r from-blue-500 to-cyan-500;
      }
    }
  }

  .form-item-tip {
    @apply mt-1 text-sm text-gray-500;
  }

  :deep(.arco-form-item-wrapper) {
    .arco-input-number {
      width: 160px;
    }
  }

  .mt-4 {
    margin-top: 16px;
  }

  .ml-2 {
    margin-left: 8px;
  }

  .ml-4 {
    margin-left: 16px;
  }

  .mx-2 {
    margin: 0 8px;
  }
}
</style>
